package cn.lili.controller.supplier;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.order.order.entity.dos.Order;
import cn.lili.modules.supplier.service.SupplierOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.Map;

/**
 * 供应商商品采集接口
 *
 * @author zhangxiaojun
 * @version v4.0
 * @Description:
 * @since 2023/10/4
 */
@RestController
@Api(tags = "供应商,商品采集接口")
@RequestMapping("/supplier/goods/collection")
@RequiredArgsConstructor
public class SupplierGoodsCollectionController {

    private final SupplierOrderService supplierOrderService;

    @PreventDuplicateSubmissions
    @ApiOperation(value = "取消订单")
    @ApiImplicitParams({@ApiImplicitParam(name = "orderSn", value = "订单编号", required = true, dataType = "String", paramType = "path"), @ApiImplicitParam(name = "reason", value = "取消原因", required = true, dataType = "String", paramType = "query")})
    @PostMapping(value = "/{orderSn}/cancel")
    public ResultMessage<Order> cancel(@ApiIgnore @PathVariable String orderSn, @RequestParam String reason) {
        return ResultUtil.data(supplierOrderService.cancel(orderSn, reason));
    }


    @PreventDuplicateSubmissions
    @ApiOperation(value = "订单发货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderSn", value = "订单sn", required = true, dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "logisticsNo", value = "发货单号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "logisticsId", value = "物流公司", required = true, dataType = "String", paramType = "query")
    })
    @PostMapping(value = "/{orderSn}/delivery")
    public ResultMessage<Object> delivery(@NotNull(message = "参数非法") @PathVariable String orderSn,
                                          @NotNull(message = "发货单号不能为空") String logisticsNo,
                                          @NotNull(message = "请选择物流公司") String logisticsId) {
        return ResultUtil.data(supplierOrderService.delivery(orderSn, logisticsNo, logisticsId));
    }


    public Map<String,Object> getGoodsGrabConfig(){
        //{"type":"99api","key":"86A3EEBE94E87596628E910E0CE7B0CA"}
        Map<String,Object> config = new HashMap<>();
        config.put("type","99api");
        config.put("key","86A3EEBE94E87596628E910E0CE7B0CA");
        return config;
    }

}
